#!/bin/bash

QIRP_SDK_DIR="/robot/target/qcm6490/qirpsdk_artifacts/qirp-sdk"
SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
PROJECT_DIR="${SCRIPT_DIR}/.."
BUILD_DIR="${PROJECT_DIR}/build"

cd "${QIRP_SDK_DIR}"
export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
source setup.sh
export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH

cd "${PROJECT_DIR}"
export AMENT_PREFIX_PATH="${OECORE_TARGET_SYSROOT}/usr;${OECORE_NATIVE_SYSROOT}/usr"
export PYTHONPATH=${PYTHONPATH}:${OECORE_TARGET_SYSROOT}/usr/lib/python3.10/site-packages

colcon build --continue-on-error --cmake-args \
  -DCMAKE_TOOLCHAIN_FILE=${OE_CMAKE_TOOLCHAIN_FILE} \
  -DPYTHON_EXECUTABLE=${OECORE_NATIVE_SYSROOT}/usr/bin/python3 \
  -DPython3_NumPy_INCLUDE_DIR=${OECORE_NATIVE_SYSROOT}/usr/lib/python3.10/site-packages/numpy/core/include \
  -DSYSROOT_LIBDIR=${OECORE_TARGET_SYSROOT}/usr/lib \
  -DSYSROOT_INCDIR=${OECORE_TARGET_SYSROOT}/usr/include \
  -DCMAKE_MAKE_PROGRAM=/usr/bin/make \
  -DBUILD_TESTING=OFF
